package com.qdu.controller;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qdu.entity.Bussiness;
import com.qdu.entity.Manager;
import com.qdu.entity.Usert;
import com.qdu.service.ManagerService;

@Controller
public class ManagerController {

	@Autowired
	private ManagerService service;
	
	@GetMapping("/manager/isDis")
	@ResponseBody
	int userstatus(String uid) {
		
		return service.userstatus(uid);
	}
	
	@RequestMapping("/manager/login")//日后用Spring security写
	public Manager loginControl(Manager tempManager) {
		Manager m= service.login(tempManager.getMid(),tempManager.getMid());
		System.out.println(m);
		System.out.println(tempManager.getMid());
		return m;
	}
	
	@GetMapping("/manager/getJobByBuss")
	@ResponseBody
	public List<Map<String,Object>> getJobByBuss(int bid){
		return service.getJobByBuss(bid);
	}
	
	@RequestMapping("/manager/getAllUser")
	@ResponseBody
	public List<Usert> UserList(){
		return service.getAllUser();
	}
	@GetMapping("/manager/unreviewed")
	@ResponseBody
	public List<Bussiness> unReviewedList(){
		return service.getUnreviewd();
	}
	
	@PostMapping("/manager/getAllH")
	@ResponseBody
	public List<Map<String,Object>> getHrList(){
		return service.getHrList();
	}
	@PostMapping("/manager/getAllB")
	@ResponseBody
	public List<Map<String,Object>> getBussList(){
		return service.getAllBuss();
	}
	
	@PostMapping("/manager/disOneB")
	@ResponseBody
	public int disOneB(String bid){
		return service.disOneBuss(bid);
	}
	
	@PostMapping("/manager/agreeOneB")
	@ResponseBody
	public int agreeOneB(String bid){
		return service.agreeOneBuss(bid);
	}
	
	@PostMapping("/manager")
	@ResponseBody
	public List<Map<String,Object>> jobList(@RequestParam Map<String,Object> map){
		//System.out.println(map.toString());
		int nextWant = Integer.parseInt((String)map.get("nextWant"));
		int number = Integer.parseInt((String)map.get("number"));
		return service.getJobList();
	}
	@PostMapping("/manager/getByTime")
	@ResponseBody
	public List<Map<String,Object>> jobListByTime(@RequestParam Map<String,Object> map){
		int nextWant = Integer.parseInt((String)map.get("nextWant"));
		int number = Integer.parseInt((String)map.get("number"));
		return service.getJobListByTime();
	}
	
	
	@PostMapping("/manager/deleteU")
	@ResponseBody
	public String deleteOneByuid(String uid) {
		int status =service.deleteUser(uid);
		if(status==200) {
			return "删除成功";
		}
		
		return "删除失败，请重试";
	}
	
	@PostMapping("/manager/disabledU")
	@ResponseBody
	public int updateUlevel(String uid) {
		int result = service.updateUserlevel(uid);
		if(result>0) {
			return 200;
		}
		return 500;
	}
	@PostMapping("/manager/enabledU")
	@ResponseBody
	public int updateUlevelEn(String uid) {
		int result = service.updateUserlevelEn(uid);
		if(result>0) {
			return 200;
		}
		return 500;
	}
	
	@PostMapping("/manager/getBussiness")
	@ResponseBody
	public List<Map<String,Object>> getBussiness(String bname){
		List<Map<String,Object>> list= service.getBussiness(bname); 
		System.out.println(bname+""+list.toString());
		return list;
		
	}
	
	@PostMapping("/manager/getSelection")
	@ResponseBody
	public List<Map<String,Object>> getJobSelection(){
		return service.getSearchList();
	}
	
	@PostMapping("/manager/getbname")
	@ResponseBody
	public List<Map<String,Object>> getBussSelection(){
		return service.getBussname();
	}
	
	@PostMapping("/manager/getbatch")
	@ResponseBody
	public List<Map<String,Object>> getBatchSelection(){
		return service.getBussbatchid();
	}
	
	@PostMapping("/manager/deleteJob")
	@ResponseBody
	public int deleteJob(@RequestParam("jid")String jid) {
		BigInteger b = new BigInteger(jid);
		return service.deleteJob(b);
	}
}
